package business.ticket;

import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;

import parameter.EntryExitType;
import parameter.TicketType;
import parameter.TradeState;
import parameter.TradeType;
import foundation.Ticket;

public class TTableFunc extends Ticket {
    
    public long CurrnetFlux(Connection conn, EntryExitType eeType) {
        long lNum = 0;
        String sTable;
        String sWhere;
        
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        this.dateStart = dateFormat.format(now);
        ;
        this.dateEnd = dateStart;
        // Single card
        ticketType.add(TicketType.PreSJT);
        ticketType.add(TicketType.SJT);
        ticketType.add(TicketType.StationWorkPass);
        ticketType.add(TicketType.SouvenirMultiride);
        ticketType.add(TicketType.Multiride);
        ticketType.add(TicketType.EmployeeTicket);
        
        tradeTpye = TradeType.SingleProduct;
        setTradeStateForFlux(eeType, false);
        
        sWhere = buildBasicWhereString(false);
        sTable = "consume_trade_ud";
        lNum = getCount(conn, sTable, sWhere);
        
        // ICCard
        tradeTpye = TradeType.ICOther;
        ticketType.clear();
        tradeState.clear();
        ticketType.add(TicketType.NormalSaleCard);
        ticketType.add(TicketType.NormalRentCard);
        ticketType.add(TicketType.ElderCard);
        ticketType.add(TicketType.StudentCard);
        ticketType.add(TicketType.SouvenirCard);
        ticketType.add(TicketType.SpecialCard);
        ticketType.add(TicketType.TianYiCard);
        ticketType.add(TicketType.TestCard);
        
        setTradeStateForFlux(eeType, true);
        
        sWhere = buildBasicWhereString(false);
        sTable = "iccard_trade_ud";
        lNum += getCount(conn, sTable, sWhere);
        
        clearTicket();
        return lNum;
    }
    
    public void setTradeStateForFlux(EntryExitType eeType, boolean iCCard) {
        if (!iCCard) {
            switch (eeType) {
                case Entry:
                    tradeState.add(TradeState.ProductPurseUseOnEntry);
                    tradeState.add(TradeState.ProductPassUseOnEntry);
                    tradeState.add(TradeState.ProductMultirideUseOnEntry);
                    tradeState.add(TradeState.ProductDelayMultirideUseOnEntry);
                    tradeState.add(TradeState.ProductDelayPassUseOnEntry);
                    tradeState.add(TradeState.ProductDelayPurseUseOnEntry);
                    break;
                case Exit:
                    tradeState.add(TradeState.ProductPurseUseOnExit);
                    tradeState.add(TradeState.ProductPassUseOnExit);
                    tradeState.add(TradeState.ProductMultirideUseOnExit);
                    tradeState.add(TradeState.ProductDelayMultirideUseOnExit);
                    tradeState.add(TradeState.ProductDelayPassUseOnExit);
                    tradeState.add(TradeState.ProductDelayPurseUseOnExit);
                    break;
                case EntryExit:
                    tradeState.add(TradeState.ProductPurseUseOnEntry);
                    tradeState.add(TradeState.ProductPassUseOnEntry);
                    tradeState.add(TradeState.ProductMultirideUseOnEntry);
                    tradeState.add(TradeState.ProductDelayMultirideUseOnEntry);
                    tradeState.add(TradeState.ProductDelayPassUseOnEntry);
                    tradeState.add(TradeState.ProductDelayPurseUseOnEntry);
                    tradeState.add(TradeState.ProductPurseUseOnExit);
                    tradeState.add(TradeState.ProductPassUseOnExit);
                    tradeState.add(TradeState.ProductMultirideUseOnExit);
                    tradeState.add(TradeState.ProductDelayMultirideUseOnExit);
                    tradeState.add(TradeState.ProductDelayPassUseOnExit);
                    tradeState.add(TradeState.ProductDelayPurseUseOnExit);
                    break;
                default:
                    break;
            }
        } else {
            switch (eeType) {
                case Entry:
                    tradeState.add(TradeState.ICEntry);
                    tradeState.add(TradeState.ICDelayEntry);
                    break;
                case Exit:
                    tradeState.add(TradeState.ICExit);
                    tradeState.add(TradeState.ICDelayExit);
                    break;
                case EntryExit:
                    tradeState.add(TradeState.ICEntry);
                    tradeState.add(TradeState.ICDelayEntry);
                    tradeState.add(TradeState.ICExit);
                    tradeState.add(TradeState.ICDelayExit);
                    break;
                default:
                    break;
            }
        }
  
    }
    
    @Override
    public long getFlux(Connection conn, EntryExitType eeType, String dateStart, String dateEnd) {
        // TODO Auto-generated method stub
        return 0;
    }
    
    @Override
    public double getCompensationFare(Connection conn, String dateStart, String dateEnd) {
        // TODO Auto-generated method stub
        return 0;
    }
    
    @Override
    public double getSale(Connection conn, String dateStart, String dateEnd) {
        // TODO Auto-generated method stub
        return 0;
    }
    
}
